package exp1.test3;
import ClassTest.Student;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Created by 春旺 on 2017/9/25.
 */
public class ListTest {
    List<Student> list= new List<>();
    Student s1 = new Student();
    @Test
    public void getCurrentSize() throws Exception {

        Student s1 = new Student();

        assertEquals(0,list.getCurrentSize());
      list.add(s1);
        assertEquals(1,list.getCurrentSize());

    }

    @Test
    public void isEmpty() throws Exception {
        assertEquals(true,list.isEmpty());
        Student s1 = new Student();
        list.add(s1);
        assertEquals(false,list.isEmpty());

    }

    @Test
    public void add() throws Exception {
        assertEquals(true,list.add(null));
        list.add(s1);
        assertEquals(true,list.add(s1));
    }

    @Test
    public void remove() throws Exception {
        list.add(s1);
        list.remove();
        assertEquals(0,list.getCurrentSize());

    }

    @Test
    public void remove1() throws Exception {
        Student s2 = new Student();
        Student s3 = new Student();
        Student s4 = new Student();
        list.add(s1);  list.add(s2);
        list.add(s3);   list.add(s4);
        list.add(s1);   list.add(s2);
        list.add(s3);  list.add(s4);
        assertEquals(8,list.getCurrentSize());
        list.remove(s2);
        assertEquals(6,list.getCurrentSize());
    }

    @Test
    public void clear() throws Exception {
        for (int i = 0;i<100;i++){
            list.add(s1);
        }
        assertEquals(100,list.getCurrentSize());
        list.clear();
        assertEquals(0,list.getCurrentSize());

    }

    @Test
    public void getFrequencyOf() throws Exception {
        Student s2 = new Student();
        Student s3 = new Student();
        for (int i = 0;i < 50;i++){
            list.add(s2);
            list.add(s1);
        }
        assertEquals(50,list.getFrequencyOf(s1));
        assertEquals(0,list.getFrequencyOf(s3));
    }

    @Test
    public void contains() throws Exception {
        Student s2 = new Student();
        Student s3 = new Student();
        for (int i = 0;i < 50;i++){
            list.add(s2);
            list.add(s1);
        }
        assertEquals(true,list.contains(s2));
        assertEquals(false,list.contains(s3));
    }

}